package cn.wiseda.finance.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wiseda.finance.entity.Bank;
import cn.wiseda.finance.entity.Organization;
import cn.wiseda.finance.services.OrganServices;

@Controller
@RequestMapping("organ")
public class OrganController {

	private static final Logger log = LoggerFactory.getLogger("OrganController");

	@Resource
	private OrganServices organServices;

	@RequestMapping("list.jhtml")
	public String list(Model model) {
		List<Organization> list = organServices.getOrganList();
		model.addAttribute("organ", list);
		return "organ/list";
	}

	@RequestMapping("save.jhtml")
	public String createBank(Organization organ, Model model) {
		boolean flag = organServices.saveOrgan(organ);
		if (flag) {
			model.addAttribute("isHide", "none");
			return "redirect:list.jhtml";
		}
		model.addAttribute("error", "<div class=\"alert alert-danger\"><strong>错误!</strong>添加信息失败！</div>");
		return "organ/list";
	}

	@RequestMapping("create.jhtml")
	public String createPage() {
		return "organ/create";
	}

	@RequestMapping("update.jhtml")
	public String getOrgan(int id, Model model) {
		Organization organ = organServices.getOrgan(id);
		model.addAttribute("organ", organ);
		return "organ/update";
	}

	@RequestMapping("modify.jhtml")
	public String modifyOrgan(Organization organ, Model model) {
		boolean flag = organServices.modifyOrgan(organ);
		if (flag) {
			model.addAttribute("isHide", "none");
			return "redirect:list.jhtml";
		}
		model.addAttribute("error", "<div class=\"alert alert-danger\"><strong>错误!</strong>修改信息失败！</div>");
		return "organ/update";
	}
}
